<?php

/**
 * Name: 风险源验证层
 * User: Silent
 * Date: 2025-09-20
 * Time: 22:43:26
 */

namespace App\Http\Requests\Safety;

use Illuminate\Foundation\Http\FormRequest;

class RiskSourceRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $rules = [
            'location'        => 'required|string|max:255',
            'description'     => 'required|string',
            'pose_risk'       => 'required|string',
            'risk_level'      => 'required|in:低风险,一般风险,较大风险,重大风险',
            'accident_type'   => 'required|max:50',
            'control_measure' => 'required|string',
        ];

        $action = optional($this->route())->getActionMethod();
        if ($action === 'update') {
            $rules['id'] = 'required|integer';
        }

        return $rules;
    }

    public function messages(): array
    {
        return [
            'location.required'        => '风险源位置不能为空',
            'description.required'     => '风险描述不能为空',
            'pose_risk.required'       => '造成风险不能为空',
            'risk_level.required'      => '风险等级不能为空',
            'risk_level.in'            => '风险等级必须是：低风险、一般风险、较大风险、重大风险中的一种',
            'accident_type.required'   => '事故类型不能为空',
            'control_measure.required' => '管控措施不能为空',
            'id.required'              => 'ID不能为空',
            'id.integer'               => 'ID必须为整数',
        ];
    }
}
